package com.muqi.app.user.widget;

import com.muqi.app.qlearn.student.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

public class UserInfoWindow extends PopupWindow implements OnClickListener {
	private View conentView;
	private Context mContext;
	
	private TextView [] tvs=new TextView[2];

	public interface ClickClubWindowListener {
		void onClickClubWindowListener(int position);
	}

	private ClickClubWindowListener clickClubWindowListener;

	@SuppressWarnings("deprecation")
	public UserInfoWindow(final Activity context,
			ClickClubWindowListener clickClubWindowListener) {
		this.clickClubWindowListener = clickClubWindowListener;
		this.mContext = context;
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		conentView = inflater.inflate(R.layout.popup_userinfo, null);
		// int h = context.getWindowManager().getDefaultDisplay().getHeight();
		int w = context.getWindowManager().getDefaultDisplay().getWidth();
		this.setContentView(conentView);
		this.setWidth(w / 3 + 110);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setOutsideTouchable(true);
		this.update();
		ColorDrawable dw = new ColorDrawable(0000000000);
		this.setBackgroundDrawable(dw);
		this.setAnimationStyle(R.style.AnimationPreview);
		LinearLayout button1 = (LinearLayout) conentView
				.findViewById(R.id.pop_button_01);
		LinearLayout button2 = (LinearLayout) conentView
				.findViewById(R.id.pop_button_02);
		tvs[0]=(TextView) conentView.findViewById(R.id.pop_tv_1);
		tvs[1]=(TextView) conentView.findViewById(R.id.pop_tv_2);
		button1.setOnClickListener(this);
		button2.setOnClickListener(this);

	}

	/**
	 * showPopupWidow
	 * 
	 * @param parent
	 */
	public void showPopupWindow(View parent) {
		if (!this.isShowing()) {
			this.showAsDropDown(parent, 0, 0);
		} else {
			this.dismiss();
		}
	}

	@Override
	public void onClick(View v) {
		if (clickClubWindowListener != null) {

			switch (v.getId()) {
			case R.id.pop_button_01:
				clickClubWindowListener.onClickClubWindowListener(1);
				break;
			case R.id.pop_button_02:
				clickClubWindowListener.onClickClubWindowListener(2);
				break;

			default:
				break;
			}
		}

		UserInfoWindow.this.dismiss();
	}
	
	public void setText(int position,String text,boolean isVisible){
		 if(tvs!=null){
			 tvs[position].setText(text);
		 }
	}
}